package edu.tyut.game.logic.network

import edu.tyut.game.logic.model.Comment
import edu.tyut.game.logic.model.Feedback
import edu.tyut.game.logic.model.FriendCircle
import edu.tyut.game.logic.model.User
import okhttp3.MultipartBody
import retrofit2.await

object GameNetWork {

    // 用户
    private val userService = ServiceCreator.create<UserService>()
    suspend fun register(user: User) = userService.register(user).await()
    suspend fun isExistUser(map: Map<String, String>) = userService.existUser(map).await()
    suspend fun login(user: User) = userService.login(user).await()
    suspend fun getUser(username: String) = userService.getUser(username).await()
    suspend fun updatePassword(user: User) = userService.updatePassword(user).await()
    suspend fun updateHeadIcon(files: List<MultipartBody.Part>) = userService.updateHeadIcon(files).await()

    // mail
    private val mailService = ServiceCreator.create<MailService>()
    suspend fun sendMail(user: User) = mailService.sendMail(user).await()
    suspend fun sendRetrievePasswordEmail(user: User) = mailService.sendRetrievePasswordEmail(user).await()

    // poem
    private val poemService = ServiceCreator.create<PoemService>()
    suspend fun getDynasties() = poemService.getDynasties().await()
    suspend fun getPoemOrderByClickCount() = poemService.getPoemOrderByClickCount().await()
    suspend fun getPoemList(dynasty: String) = poemService.getPoemListByDynasty(dynasty).await()
    suspend fun getSearchPoemList(content: String) = poemService.getPoemListBySearch(content).await()
    suspend fun poemRecommend(ids: String) = poemService.poemRecommend(ids).await()

    // feedback
    private val feedbackService = ServiceCreator.create<FeedbackService>()
    suspend fun sendFeedback(feedback: Feedback) = feedbackService.sendFeedback(feedback).await()

    // FlyingFlowerOrder
    private val flyingFlowerOrderService = ServiceCreator.create<FlyingFlowerOrderService>()
    suspend fun getContentsByWord(words: String) = flyingFlowerOrderService.getContentsByWord(words).await()
    suspend fun gameOver(uid: Int) = flyingFlowerOrderService.gameOver(uid).await()
    suspend fun isExistPoem(content: String) = flyingFlowerOrderService.isExistPoem(content).await()
    suspend fun win(uid: Int) = flyingFlowerOrderService.win(uid).await()
    suspend fun lose(uid: Int) = flyingFlowerOrderService.lose(uid).await()
    suspend fun getWinRateRank() = flyingFlowerOrderService.getWinRateRank().await()
    suspend fun getTotalRoundsRank() = flyingFlowerOrderService.getTotalRoundsRank().await()
    suspend fun getWinRateRankTotalRoundsRank() = flyingFlowerOrderService.getWinRateRankTotalRoundsRank().await()

    // FriendCircle
    private val friendCircleService = ServiceCreator.create<FriendCircleService>()
    suspend fun postFriendCircle(parts: List<MultipartBody.Part>) = friendCircleService.postFriendCircle(parts).await()
    suspend fun deleteFriendCircle(fcId: Int) = friendCircleService.deleteFriendCircle(fcId).await()
    suspend fun updateFriendCircle(parts: List<MultipartBody.Part>) = friendCircleService.updateFriendCircle(parts).await()
    suspend fun queryFriendCircle(order: String) = friendCircleService.queryFriendCircle(order).await()
    suspend fun addFriendCircleLike(fcId: Int) = friendCircleService.addFriendCircleLike(fcId).await()
    suspend fun subFriendCircleLike(fcId: Int) = friendCircleService.subFriendCircleLike(fcId).await()
    suspend fun postComment(comment: Comment) = friendCircleService.postComment(comment).await()
    suspend fun deleteComment(commentId: Int) = friendCircleService.deleteComment(commentId).await()
    suspend fun queryComment(fcId: Int) = friendCircleService.queryComment(fcId).await()
    suspend fun addCommentLike(commentId: Int) = friendCircleService.addCommentLike(commentId).await()
    suspend fun subCommentLike(commentId: Int) = friendCircleService.subCommentLike(commentId).await()
}